home *** CD-ROM | disk | FTP | other *** search
/ Interactive Web Graphics with Shout 3D / Interactive Web Graphics With Shout 3D.iso / pc / Code / Chapter11 / ScanTheSkiesDisplay.java < prev    next >
Text File  |  2000-07-25  |  2KB  |  65 lines

  1.  
  2. package custom_nodes;
  3.  
  4. import shout3d.core.*;
  5. import shout3d.*;
  6. import java.awt.*;
  7.  
  8.  
  9. public class ScanTheSkiesDisplay extends PostRenderEffect{
  10.  
  11.  
  12.    final public IntField  score = new IntField(this, "score", Field.NON_NEGATIVE_INT, 0);
  13.    
  14.    final public IntField  shotClock = new IntField(this, "shotClock", Field.NON_NEGATIVE_INT, 0);
  15.  
  16.    //constructor
  17.    public ScanTheSkiesDisplay(){
  18.    
  19.    }
  20.  
  21.    
  22.    public void filter(Graphics g, int surface_pixel_bits[], float z_buffer[], int deviceWidth, int deviceHeight){
  23.    
  24.       //initialize display strings   
  25.       String scoreString = ""+score.getValue();
  26.       String clockString = ""+shotClock.getValue();
  27.       String message = "CLICK TO START";
  28.  
  29.  
  30.       //if shot clock is at zero
  31.       //display CLICK TO START
  32.       if (shotClock.getValue() == 0) {
  33.  
  34.             Font f = new Font("SansSerif", Font.BOLD, 30);
  35.             FontMetrics fm = g.getFontMetrics(f);
  36.             int stringWidth = fm.stringWidth(message);
  37.             g.setFont(f);
  38.             g.setColor(java.awt.Color.yellow);
  39.             g.drawString(message, (deviceWidth - stringWidth)/2, deviceHeight/2);
  40.  
  41.       }
  42.       
  43.       //if game is running
  44.       //draw sight rectangle
  45.       else {
  46.          //red in final 3 seconds
  47.          //as warning
  48.          if (shotClock.getValue() < 4) {
  49.             g.setColor(java.awt.Color.red);         
  50.          }
  51.          //otherwise yellow
  52.          else {
  53.             g.setColor(java.awt.Color.yellow);
  54.          }      
  55.          g.drawRect((deviceWidth/2)-25, (deviceHeight/2)-25, 50, 50);  
  56.       }
  57.       
  58.       //set up score and shot clock display
  59.       g.setFont( new Font("SansSerif", Font.BOLD, 16));
  60.       g.setColor(java.awt.Color.yellow); 
  61.       g.drawString(scoreString, deviceWidth - 50, 30);
  62.       g.drawString(clockString, 50, 30);
  63.       
  64.    }
  65. }